package com.juc.learn.collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

/**
 * ClassName:ThreadDemo
 * Package:com.juc.learn.collections
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/27 - 8:59
 * @Version:v1.0
 */
public class ThreadDemo {
    public static void main(String[] args) {
        //使用工具类解决线程的并发读写问题
        List<String> list = Collections.synchronizedList(new ArrayList<>());
        //创建多个线程，往集合中加入元素和取出元素
        for (int i = 0; i < 130; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0, 4));
                System.out.println(list);
            }, "线程" + String.valueOf(i)).start();
        }
    }
}
